package com.company.cloud.goodsrestservice.service.impl;

import com.company.cloud.goodsrestservice.core.AbstractService;
import com.company.cloud.goodsrestservice.dao.CategoryMapper;
import com.company.cloud.goodsrestservice.model.Category;
import com.company.cloud.goodsrestservice.service.CategoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * Created by reabout on 2018/03/24.
 */
@Service
@Transactional
public class CategoryServiceImpl extends AbstractService<Category> implements CategoryService {
    @Resource
    private CategoryMapper goodsCategoryMapper;

    private final Logger log = LoggerFactory.getLogger(CategoryService.class);

    public Category chkInsert(String name) {
        Category category = findBy("categoryName", name);
        if (category == null & name != "") {
            log.info("New category {}", name);
            category = new Category();
            category.setCategoryName(name);
            category.setCategoryMark("gom");
            category.setParentId(-1);
            category.setCreateTime(System.currentTimeMillis());
            category.setStatus(2);
            save(category);
            category = findBy("categoryName", name);
        }
        return category;
    }

}
